local yunxi = fk.CreateSkill{
    name = "jinld__yunxi_other",
    tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
    ["jinld__yunxi_other"] = "允玺",
    [":jinld__yunxi_other"] = "锁定技，若场上没有【玉玺】，你摸牌阶段额外摸一张牌；出牌阶段开始时，若场上存在【玉玺】，你获得之。",
}

-- 没有角色有玉玺
---@param player Player
---@return boolean
local canYongsi = function (player)
  return not table.find(Fk:currentRoom().alive_players, function(p)
    return not not table.find(p:getEquipments(Card.SubtypeTreasure), function(cid)
      return Fk:getCardById(cid).name == "jade_seal"
    end)
  end)
end

yunxi:addEffect(fk.DrawNCards,{
    anim_type = "drawcard",
    can_trigger = function (self, event, target, player, data)
        return target == player and player:hasSkill(yunxi.name) and canYongsi(player)
    end,
    on_use = function (self, event, target, player, data)
        data.n = data.n + 1
    end,
})

yunxi:addEffect(fk.EventPhaseStart,{
    anim_type = "control",
    can_trigger = function (self, event, target, player, data)
        return target == player and player:hasSkill(yunxi.name) and not canYongsi(player) and player.phase == Player.Play
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local to = table.filter(room.alive_players, function(p) return not not table.find(p:getEquipments(Card.SubtypeTreasure), function(cid)
        return Fk:getCardById(cid).name == "jade_seal" end) end)
        if #to == 0 then return end
        room:obtainCard(player, to[1]:getEquipments(Card.SubtypeTreasure), true, fk.ReasonJustMove, player, yunxi.name)
    end,
})

return yunxi